package controller

import (
	"context"
	"lot_admin_api/api"
	"lot_admin_api/internal/model"
	"lot_admin_api/internal/service"
)

var Equipment = cEquipment{}

type cEquipment struct{}

// AddEquipment  新增设备
func (h *cEquipment) AddEquipment(ctx context.Context, req *api.AddEquipmentReq) (res *model.EquipmentIdRes, err error) {
	id, _ := service.Equipment().AddEquipment(ctx, req)
	res = &model.EquipmentIdRes{
		Id: id,
	}
	return res, err
}

// EditEquipment  编辑设备的基本信息
func (h *cEquipment) EditEquipment(ctx context.Context, req *api.EditEquipmentReq) (res *model.EquipmentIdRes, err error) {
	id, _ := service.Equipment().EditEquipment(ctx, req)
	res = &model.EquipmentIdRes{
		Id: id,
	}
	return res, err
}

// EquipmentInfo  获取设备的基本信息
func (h *cEquipment) EquipmentInfo(ctx context.Context, req *api.EquipmentInfoReq) (res *model.EquipmentDbInfoPortRes, err error) {
	res, err = service.Equipment().SearchEquipmentInfo(ctx, req.Id)
	return res, err
}

// DeleteEquipment  删除设备的基本信息
func (h *cEquipment) DeleteEquipment(ctx context.Context, req *api.DeleteEquipmentReq) (res *model.EquipmentIdRes, err error) {
	id, err := service.Equipment().DeleteEquipment(ctx, req)
	res = &model.EquipmentIdRes{
		Id: id,
	}
	return res, err
}

// EquipmentList  获取设备列表
func (h *cEquipment) EquipmentList(ctx context.Context, req *api.EquipmentListReq) (res *model.EquipmentListPageRes, err error) {
	res, err = service.Equipment().EquipmentList(ctx, req)
	return res, err
}

// EditEquipmentPortStatus  修改设备端口的状态
func (h *cEquipment) EditEquipmentPortStatus(ctx context.Context, req *api.EditEquipmentPortStatusReq) (res *model.EquipmentPortIdRes, err error) {
	id, err := service.EquipmentPort().EditEquipmentPortStatus(ctx, req.EditEquipmentPortStatus)
	res = &model.EquipmentPortIdRes{
		Id: id,
	}
	return res, err
}
